﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

/// <summary>
/// Summary description for Menu
/// </summary>
public class Menu
{
   
    DanhMucDA getDM = new DanhMucDA();
    LoaiDA getLoai = new LoaiDA();
    ChucNangDA getCN = new ChucNangDA();
    public string buildTopMenu()
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("<ul id='sidebarmenu1'>");

        foreach (DanhMuc objDM in getDM.GetData())
        {
            builder.Append("<li><a href='Product.aspx?category=" + objDM.Id + "'>" + objDM.Name + "</a>");

            builder.Append(buildSubMenuLoai(objDM.Id));

            builder.Append("</li>");
        }
        builder.Append("</ul>");
        return builder.ToString();
    }

    public string buildOtherMenu() {
        StringBuilder builder = new StringBuilder();
        builder.Append("<ul id='sidebarmenu2'>");

        foreach (DanhMuc objDM in getDM.GetOther())
        {          
            builder.Append(buildSubMenuLoaiOther(objDM.Id));
        }
        builder.Append("</ul>");
        return builder.ToString();
    }

    public string buildSubMenuLoaiOther(int danhmucID)
    {
        StringBuilder builder = new StringBuilder();
       
        foreach (Loai objLoai in getLoai.GetData(danhmucID))
        {
            builder.Append("<li><a href='Product.aspx?cate=" + objLoai.Id + "'>" + objLoai.Tenloai + "</a>");
            builder.Append(BuildSubMenuChucNang(danhmucID, objLoai.Id));
            builder.Append("</li>");
        }
       
        return builder.ToString();
    }
    public string buildSubMenuLoai(int danhmucID)
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("<ul>");
        foreach (Loai objLoai in getLoai.GetData(danhmucID))
        {
            builder.Append("<li><a href='Product.aspx?cate=" + objLoai.Id + "'>" + objLoai.Tenloai + "</a>");
            builder.Append(BuildSubMenuChucNang(danhmucID,objLoai.Id));
           builder.Append("</li>");
        }
        builder.Append("</ul>");
        return builder.ToString();
    }

    public string BuildSubMenuChucNang(int danhmucID,int loaiID)
    {
        StringBuilder builder = new StringBuilder();
        
        foreach (ChucNang objCN in getCN.GetData(loaiID,danhmucID))
        {
		builder.Append("<ul>");	
            builder.Append("<li><a href='Product.aspx?cate=" + loaiID + "&chucnangID=" + objCN.Id + "'>" + objCN.Ten + "</a></li>");
	builder.Append("</ul>");        
}
        

        return builder.ToString();
    }
}